﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.EntityModel;

namespace MonkeyWarranty.Web.Products
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static ProductBiz _productBiz;
        private static ProductBiz ProductManager
        {
            get { return _productBiz ?? (_productBiz = new ProductBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var groups = ProductManager.GetAllProductGroups();
                groups.Insert(0, new ProductGroup { Id = 0, Name = Resources.GlobalStrings.AllGroups });
                ddlProductGroups.DataTextField = "Name";
                ddlProductGroups.DataValueField = "Id";
                ddlProductGroups.DataSource = groups;
                ddlProductGroups.DataBind();

                var manufacturers = ProductManager.GetAllManufacturers();
                manufacturers.Insert(0, new Manufacturer { Id = 0, Name = Resources.GlobalStrings.AllManufacturers });
                ddlManufacturers.DataTextField = "Name";
                ddlManufacturers.DataValueField = "Id";
                ddlManufacturers.DataSource = manufacturers;
                ddlManufacturers.DataBind();
            }
        }

        #region Product Methods

        [WebMethod(EnableSession = true)]
        public static object ProductListByFilter(string name, int productGroupId, int manufacturerId, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return ProductManager.ProductListByFilterWs(name, productGroupId, manufacturerId, jtStartIndex, jtPageSize, jtSorting);
        }

        [WebMethod(EnableSession = true)]
        public static object CreateProduct(Product record)
        {
            return ProductManager.CreateProductWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object UpdateProduct(Product record)
        {
            return ProductManager.UpdateProductWs(record);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteProduct(int Id)
        {
            return ProductManager.DeleteProductWs(Id);
        }

        #endregion

        #region ProductGroup Methods

        [WebMethod(EnableSession = true)]
        public static object GetProductGroupOptions()
        {
            return ProductManager.GetProductGroupOptionsWs();
        }

        #endregion

        #region Manufacturer Methods

        [WebMethod(EnableSession = true)]
        public static object GetManufacturerOptions()
        {
            return ProductManager.GetManufacturerOptionsWs();
        }

        #endregion
    }
}